package com.luo.controller;

import com.luo.pojo.Works;
import com.luo.service.works.WorksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;

@RestController

public class WorksController {
    @Autowired
    private WorksService worksService;
    @GetMapping("/works")
    public List<Works> worksController(HttpServletRequest request) throws ParseException {
        List<Works> worksList = worksService.queryAllworks();
        for (Works work : worksList) {
            String[] works = worksService.queryWorkTags(work.getWid());
            work.setDate(work.getDate().substring(0,4)+"."+work.getDate().substring(5,7));
            work.setTags(works);
        }
        request.setAttribute("works", worksList);
        return worksList;
    }
}
